function getYearAjax(uid){


    var myuid = uid;


    var ip = ip_port;
   // if(myuid==null||myuid==""||myuid==undefined){
   //      window.parent.location.href=ip + "front/tologin";
   // }
    var option={
        type:"post",
        data:"uid="+myuid + "&year=" + $("#yearSelct").val(),
        success:function (msg) {
            showYearReport(msg.sumshou,msg.sumzhi);
        },
        beforeSend:function (xhr) {
            if(myuid==null||myuid==""){
                return false;
            }
        },
        error:function (error) {
            alert("error");
        }
    };
    $.ajax(ip + "report/sumshouzhidata",option);
}
/**
 * 图形显示
 * @param sumshou
 * @param sumzhi
 */
function showYearReport(sumshou,sumzhi){

    if (sumshou.money==null){

        sumshou.money=0;
    }
    if (sumzhi.money==null){

        sumzhi.money=0;
    }

    year_option = {
        title : {
            text: '年收支报表',
            subtext: '元'
        },
        tooltip : {
            trigger: 'axis'
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                data : ['收入','支出'],
                splitLine:{
                    show:false
                },
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value',
                splitLine:{
                    show:false
                },
                splitArea:{
                    show:true,
                },
            }
        ],
        series : [
            {
                name:'金额',
                type:'bar',
                label:{
                    normal:{
                        show:true,
                        position:'top'
                    }
                },
                itemStyle:{
                    normal:{
                        color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                    }
                },
                data:[sumshou.money, sumzhi.money],
            }
        ]
    };

    var myChart = echarts.init(document.getElementById('shouzhi_rep'));
    myChart.setOption(year_option);

}

function getJiduAjax(uid){
    var myuid = uid;
    var ip = ip_port;
    if(myuid==null||myuid==""){
        window.parent.location.href=ip + "front/tologin";
    }
    var option={
        type:"post",
        data:"uid="+myuid + "&year=" + $("#yearSelct").val(),
        success:function (msg) {
            showJiduReport(msg.sumJiduShouDtoList,msg.sumJiduZhiDtoList);
        },
        beforeSend:function (xhr) {
            if(myuid==null||myuid==""){
                return false;
            }
        },
        error:function (error) {
            alert("error");
        }
    };
    $.ajax(ip + "report/sumjidushouzhidata",option);
}
/**
 * 图形显示
 * @param sumshou
 * @param sumzhi
 */
function showJiduReport(sumjidushou,sumjiduzhi){

    var arrShou = [];
    var arrZhi =[];

    for (var i=0;i<sumjidushou.length;i++){
        if (sumjidushou[i]==null){
            arrShou.push(0);
        }else{
            arrShou.push(sumjidushou[i].money);
        }
    }
    for (var i=0;i<sumjiduzhi.length;i++){
        if (sumjiduzhi[i]==null){
            arrZhi.push(0);
        }else{
            arrZhi.push(sumjiduzhi[i].money);
        }
    }
    jidu_option = {

        title : {
            text: '季支出报表',
            subtext: '元'
        },
        tooltip : {
            trigger: 'axis'
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                data : ['第一季度','第二季度','第三季度','第四季度'],
                splitLine:{
                    show:false
                },
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value',
                splitLine:{
                    show:false
                },
                splitArea:{
                    show:true,
                },
            }
        ],
        series : [
            {
                name:'支出',
                type:'bar',
                label:{
                    normal:{
                        show:true,
                        position:'top'
                    }
                },
                itemStyle:{
                    normal:{
                        color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                    }
                },
                data:arrZhi,
            },
            {
                name:'收入',
                type:'bar',
                label:{
                    normal:{
                        show:true,
                        position:'top'
                    }
                },
                itemStyle:{
                    normal:{
                        color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                    }
                },
                data:arrShou,
            }
        ]
    };


    var myChart = echarts.init(document.getElementById('shouzhi_rep'));
    myChart.setOption(jidu_option);

}

function getMonthAjax(uid){
    var myuid = uid;
    var ip = ip_port;
    if(myuid==null||myuid==""){
        window.parent.location.href=ip + "front/tologin";
    }
    var option={
        type:"post",
        data:"uid="+myuid + "&year=" + $("#yearSelct").val(),
        success:function (msg) {
            showMonthReport(msg.sumMonthShouDtoList,msg.sumMonthZhiDtoList);
        },
        beforeSend:function (xhr) {
            if(myuid==null||myuid==""){
                return false;
            }
        },
        error:function (error) {
            alert("error");
        }
    };
    $.ajax(ip + "report/summonthshouzhidata",option);
}
function showMonthReport(summonthshou,summonthzhi){

    var arrShou = [];
    var arrZhi =[];

    for (var i=0;i<summonthshou.length;i++){
        if (summonthshou[i]==null){
            arrShou.push(0);
        }else{
            arrShou.push(summonthshou[i].money);
        }
    }
    for (var i=0;i<summonthzhi.length;i++){
        if (summonthzhi[i]==null){
            arrZhi.push(0);
        }else{
            arrZhi.push(summonthzhi[i].money);
        }
    }
   var  mon_option = {
        title : {
            text: '月收支报表',
            subtext: '元'
        },
        tooltip : {
            trigger: 'axis'
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
                splitLine:{
                    show:false
                },
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value',
                splitLine:{
                    show:false
                },
                splitArea:{
                    show:true,
                },
            }
        ],
        series : [
            {
                name:'支出',
                type:'bar',
                label:{
                    normal:{
                        show:true,
                        "textStyle": {
                            "color": "#333",
                            "fontSize":5
                        },
                        position:'top',
                        "fontSize":2
                    }
                },
                itemStyle:{
                    normal:{
                        color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                    }
                },
                data:arrZhi,
            },
            {
                name:'收入',
                type:'bar',
                label:{
                    normal:{
                        show:true,
                        position:'top'
                    }
                },
                itemStyle:{
                    normal:{
                        color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                    }
                },
                data:arrShou,
            }
        ]
    };


    var myChart = echarts.init(document.getElementById('shouzhi_rep'));
    myChart.setOption(mon_option);

}

$(function () {

    var flag = "year";

    // $("#monSelct").hide();
    // $("#jiduSelct").hide();
    $("#monBtn").addClass("vist");
    $("#jiduBtn").addClass("vist");
    $("#yearBtn").addClass("vist");

    $("#yearBtn").addClass("active");
    console.log($("#uid").val());


    $("#yearBtn").click(function () {
        $("#yearBtn").addClass("vist");
        $("#yearBtn").addClass("active");
        $("#monBtn").removeClass("active");
        $("#jiduBtn").removeClass("active");
        $("#yearSelct").show();
        $("#monSelct").hide();
        $("#jiduSelct").hide();
        getYearAjax($("#uid").val());

        $("#yearSelct").unbind().change(function () {

            getYearAjax($("#uid").val());
        });
    });
    $('#yearBtn').trigger("click");

    $("#monBtn").click(function () {

        $("#monBtn").addClass("active");
        $("#yearBtn").removeClass("active");
        $("#jiduBtn").removeClass("active");
        $("#yearSelct").show();
        $("#monSelct").show();
        $("#jiduSelct").hide();

        getMonthAjax($("#uid").val());
        $("#monSelct").unbind().change(function () {
            getMonthAjax($("#uid").val());

        })
        $("#yearSelct").unbind().change(function () {

            getMonthAjax($("#uid").val());

        });
    });
    $("#jiduBtn").click(function () {

        $("#jiduBtn").addClass("active");
        $("#yearBtn").removeClass("active");
        $("#monBtn").removeClass("active");
        $("#yearSelct").show();
        $("#monSelct").hide();
        $("#jiduSelct").show();
        getJiduAjax($("#uid").val());

        $("#yearSelct").unbind().change(function () {

            getJiduAjax($("#uid").val());
        });
        $("#jiduSelct").unbind().change(function () {

            getJiduAjax($("#uid").val());
        });
    });



})